﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Data.SqlClient;
using System.Data;
using WebApplication1.Common;
using WebApplication1.Models;

namespace WebApplication1.BLL
{
    public class AppAboutBLL
    {
        /// <summary>
        /// 关于我们
        /// </summary>
        /// <returns></returns>
        public string GetAboutUs()
        {
            string sql = "SELECT top 1 [aboutId],[aboutUS],[createTime] FROM [dbo].[T_AboutUS] order by [createTime] desc";
            DataTable dt = SQLHepler.GetDataSet(sql).Tables[0];
            if (dt != null && dt.Rows.Count > 0)
            {
                string about = dt.Rows[0]["aboutUS"].GetType() == typeof(System.DBNull) ? "" : Convert.ToString(dt.Rows[0]["aboutUS"]);
                return about;
            }
            return "";
        }

        /// <summary>
        /// 根据班级id查询签到视频查看截止日期
        /// </summary>
        /// <param name="classId"></param>
        /// <returns></returns>
        public GetQvEndDate GetQvEndDate(string classId, out string qvEndDate)
        {
            GetQvEndDate model = new Models.GetQvEndDate();
            string sql = "SELECT Convert(varchar(20),[qvEndDate],23) as [qvEndDate] FROM [YouErYuanDB].[dbo].[T_Class] where [id]=@id";
            object dateObj = SQLHepler.GetSingleValue(sql, new SqlParameter("@id", classId));
            if (dateObj == null)
            {
                qvEndDate = "未定义截止日期";
                model.state = 0;
                model.dateTxt = "未定义截止日期";
                return model;
            }
            else
            {
                if (dateObj.GetType() == typeof(System.DBNull))
                {
                    qvEndDate = "未定义截止日期";
                    model.state = 0;
                    model.dateTxt = "未定义截止日期";
                    return model;
                }
                else
                {
                    qvEndDate = "";
                    string date = Convert.ToString(dateObj);
                    qvEndDate = date;
                    DateTime dateEnd = Convert.ToDateTime(dateObj).Date;
                    int bizhi = DateTime.Now.Date.CompareTo(dateEnd);
                    if (bizhi == 1)
                    {
                        model.state = 1;
                        model.dateTxt = "已到期";
                    }
                    else
                    {
                        model.state = 0;
                        model.dateTxt = date;
                    }
                }
            }
            return model;
        }
    }
}
